#!/bin/sh
set -ex

if [ -z "$1" ]; then
   echo "ERROR: no arguments, expect [spring.profiles.active]：dev, test, prod"
    exit 0
fi
PROFILE=$1
if [ $PROFILE != "dev" -a $PROFILE != "test" -a $PROFILE != "prod" ] ;then
   echo "ERROR: you input [spring.profiles.active] is $PROFILE, but expect：dev, test, prod"
   exit 0
fi
echo "[spring.profiles.active]: $PROFILE"


## 源码拉取
git pull

## 路径检测
if [ ! -d ./docker_deploy ]; then
 sudo mkdir -p docker_deploy/conf
 sudo mkdir -p docker_deploy/lib
 sudo mkdir -p docker_deploy/log
fi

## 打包
mvn -Dmaven.test.skip=true clean compile package -f pom.xml -P $PROFILE

cp target/urule-springboot-dgstar-0.0.1-SNAPSHOT.jar docker_deploy/lib
#将docker-compose.yml文件拷贝到部署目录
cp docker-compose.yml docker_deploy/

## 服务启动
echo 'docker-compose 服务即将启动..'
cd docker_deploy
docker-compose -p urule-springboot-dgstar down
docker-compose -p urule-springboot-dgstar up -d

